package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.StaffBean;
import com.project.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("staff")
public class StaffController {
    @Autowired
    private IStaffService service;

    @RequestMapping("findByItem")
    public String findByItem(@RequestParam(value = "pageNO", defaultValue = "1") Integer pageNO, Integer startMoney,
                             Integer endMoney, String position, HttpServletRequest req) {
        IPage ip = service.findByItem(pageNO, startMoney, endMoney, position);
        req.setAttribute("ipage", ip);
        req.setAttribute("startMoney", startMoney);
        req.setAttribute("endSalary", endMoney);
        req.setAttribute("dept", position);
        return "/index.html";
    }

    @RequestMapping("add")
    public String add() {
        return "/add.html";
    }

    @RequestMapping("addStaff")
    public String addStaff(StaffBean staffBean) {
        service.add(staffBean);
        return "redirect:/staff/findByItem";
    }

    @RequestMapping("del")
    public String del(Integer id) {
        service.del(id);
        return "redirect:/staff/findByItem";
    }

    @RequestMapping("findById")
    public String findById(Integer id, HttpServletRequest req) {
        StaffBean st = service.findById(id);
        req.setAttribute("st", st);
        return "/update.html";
    }

    @RequestMapping("update")
    public String update(Integer id, Integer money) {
        service.update(id, money);
        return "redirect:/employee/findByItem";
    }
}
